package com.sherlochao.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.sherlochao.dao.PhotoDao;
import com.sherlochao.model.Photo;

@Repository("photoDao")
public class PhotoDaoImpl implements PhotoDao{
	
	@Resource
	private SessionFactory sessionFactory;
	
	public Session getSession(){
		return sessionFactory.getCurrentSession();
	}

	@Override
	public Photo get(String id) {
		return null;
	}

	@Override
	public String save(Photo entity) {
		return (String)this.getSession().save(entity);
	}

	@Override
	public void delete(String id) {
		
	}

	@Override
	public Photo load(String id) {
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Photo> getPhotoByCommentId(String commentId) {
		String hql = "from Photo where comment_id = ?";
		Query query = this.getSession().createQuery(hql);
		query.setString(0, commentId);
		List<Photo> Photo = query.list();
		return Photo;
	}
}
